//
//  fileread.cpp
//  glwftry
//
//  Created by 李培根 on 2020/8/27.
//  Copyright © 2020 李培根. All rights reserved.
//

#include "fileread.hpp"
#include <stdlib.h>

char *getFileContent(const char *filePath){
    FILE *fp = fopen(filePath, "r");
    if (fp == NULL) {
        printf("Fail to open file!\n");
    }
    long fileSize = 0;
    char* vertex_shader = NULL;
    
    //Getting File Size
    fseek(fp, 0, SEEK_END);
    fileSize = ftell(fp);
    rewind(fp);
    
    //Reading From File
    vertex_shader = (char*)malloc( sizeof( char) * (fileSize+1) );
    fread(vertex_shader, sizeof(char), fileSize, fp);
    vertex_shader[fileSize] = '\0';
    fclose(fp);
    return vertex_shader;
}
